<?php
namespace app\common\model;
use app\common\model\Base;
class Scar extends Base
{
    protected $auto = [];
    protected $insert = [];
    protected $update = [];
    public function _filter($data){
        if($data['date']){
            $stime =0;
            $etime =0;
            if(strpos('至',$data['date'])){
                $date = explode('至', $data['date']);
                $stime = strtotime($date[0]);
                $etime = strtotime($date[1]);
            }else{
                $stime = strtotime($data['date'].'-01');
                $date = new \DateTime(date('Y-m-d',$stime));
                $etime = $date->add(new \DateInterval('P1M'))->getTimestamp();
            }
            $data['date']=['between',[date('Y-m-d',$stime),date('Y-m-d',$etime)]];
        }
        if($data['out_date']){
            $stime =0;
            $etime =0;
            if(strpos('至',$data['out_date'])){
                $date = explode('至', $data['out_date']);
                $stime = strtotime($date[0]);
                $etime = strtotime($date[1]);
            }else{
                $stime = strtotime($data['out_date'].'-01');
                $date = new \DateTime(date('Y-m-d',$stime));
                $etime = $date->add(new \DateInterval('P1M'))->getTimestamp();
            }
            $data['out_date']=['between',[date('Y-m-d',$stime),date('Y-m-d',$etime)]];
        }
        if($data['txrq']!=""){
            $stime = strtotime($data['txrq']);
            $date = new \DateTime(date('Y-m-d',$stime));
            $etime = date('Y-m-d',$date->sub(new \DateInterval('P1M'))->getTimestamp());

            $data['date'] = ['elt',$etime];
        }
        unset($data['txrq']);
        if($data['outprice']){
            if($data['outprice']=='1'){
                $data['outprice'] = ['gt',0];
            }
        }
    	return $data;
    }
    public function setCreateTimeAttr($value,$data)
    {
        return time();
    }

    public function setUpdateTimeAttr($value,$data)
    {
        return time();
    }
}
